package com.enjoy.jvm.hotspot.src.share.vm.oops;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@Data
public class InstanceKlass extends Klass {

    /**
     * 魔数
     */
    private final byte[] magic = new byte[4];

    /**
     * 次版本号
     */
    private final byte[] minorVersion = new byte[2];

    /**
     * 主版本号
     */
    private final byte[] majorVersion = new byte[2];

    private ConstantPool constantPool;

    private int accessFlag;
    private int thisClass;
    private int superClass;


    /**
     * 接口信息
     */
    private int interfacesLength;
    private final List<InterfaceInfo> interfaceInfos = new ArrayList<>();

    /**
     * 字段信息
     */
    private int fieldsLength;
    private final List<FieldInfo> fields = new ArrayList<>();

    private int methodLength;
    private MethodInfo[] methods;

    private int attributeLength;
    private final List<AttributeInfo> attributeInfos = new ArrayList<>();

    public InstanceKlass() {
        constantPool = new ConstantPool();
        this.constantPool.setKlass(this);
    }

    public void initMethodsContainer() {
        this.methods = new MethodInfo[methodLength];
    }

    @Override
    public String toString() {
        return "InstanceKlass{}";
    }


    public void setAccessFlag(int accessFlag) {
        this.accessFlag = accessFlag;
    }

    public void setThisClass(int thisClass) {
        this.thisClass = thisClass;
    }

    public void setSuperClass(int superClass) {
        this.superClass = superClass;
    }

    public void setInterfacesLength(int interfacesLength) {
        this.interfacesLength = interfacesLength;
    }

    public void setFieldsLength(int fieldsLength) {
        this.fieldsLength = fieldsLength;
    }

    public void setMethodLength(int methodLength) {
        this.methodLength = methodLength;
    }

    public void setMethods(MethodInfo[] methods) {
        this.methods = methods;
    }

    public void setAttributeLength(int attributeLength) {
        this.attributeLength = attributeLength;
    }

}
